package cn.ococci.dm.Main;

import org.litepal.crud.DataSupport;

import java.util.ArrayList;
import java.util.List;

import cn.ococci.dm.Main.Model.DoorModel;
import cn.ococci.dm.Main.Model.DoorUnitModel;
import cn.ococci.dm.Main.Model.UnitModel;
import cn.ococci.dm.Main.Tools.DbTool;

/**
 * Created by cyan on 16/1/17.
 * 数据构建
 */
public class DataBuilder {

    public static void addDataWithScanWiFi(List<DoorModel> tmpList,ArrayList<DoorModel> doorList){

        if (tmpList.isEmpty()){
            return;
        }

        int i = 1;
        for (DoorModel tmp:tmpList ) {

            doorList.add(i++,tmp);
        }

    }


    /**
     * 构建需要保存的数据
     * @param curDoor
     * @param selectedUnitModelList
     */
    public static void builderDataWithSaveToDb(DoorModel curDoor,List<UnitModel> selectedUnitModelList){

        curDoor.setDoorMac(curDoor.getWifiBssid());
        curDoor.setSyn(1);
        curDoor.update(curDoor.getId());

        List<DoorUnitModel> unitModelList = new ArrayList<>();
        for (UnitModel unitModel:selectedUnitModelList){

            DoorUnitModel doorUnitModel = new DoorUnitModel();

            doorUnitModel.setDoorId((int)curDoor.getDoorId());
            doorUnitModel.setDoorName(curDoor.getDoorName());
            doorUnitModel.setUnitId((int)unitModel.getUnitId());
            doorUnitModel.setUnitCode(unitModel.getUnitCode());
            doorUnitModel.setUnitName(unitModel.getUnitName());

            unitModelList.add(doorUnitModel);
        }

        DataSupport.saveAll(unitModelList);

    }



}
